<?php
/**
 * @desc layout  class file
 * @author nana
 * @date 2011
 *
 */
class Niced_TemplateManager
{
	
	protected static $data = array();

    public function __construct() 
	{ 
		//'layout manager can  not be a object, must use static';
	}

    protected static function data() 
	{
		$data = &self::$data;

        if (isset($data))
		{
            return $data;
		}

        $data = new NICED_Container();

        $data->set('script_js', array());
        $data->set('script_css', array());
        $data->set('script_css_ie', array());

        return $data;
    }

	//public static function loadJs($path, $filename) 
	//{
	//	echo '<script type="text/javascript" src="'.rtrim($path, '/').'/'.ltrim($filename, '/')."?".SC::get('board_config.version').'"></script>';
	//}

	//public static function loadCss($path, $filename) 
	//{
	//	echo '<link rel="stylesheet" type="text/css" media="all" href="'.rtrim($path, '/').'/'.ltrim($filename, '/')."?".SC::get('board_config.version').'" />';
	//}

    /*
     * @param string $file,relative to js base path
     */
	public static function loadJs($file, $protocol = false) 
	{
		$str = '<script type="text/javascript" src="'.NICED_URL::buildJsURL($file, $protocol).'"></script>';

        echo $str;
	}

	public static function loadCss($file, $protocol = false) 
	{
		$str = '<link rel="stylesheet" type="text/css" media="all" href="'.NICED_URL::buildCssURL($file, $protocol).'" />';

        echo $str;
	}

    public static function loadImage($file, $protocol = false, $attr = "")
    {
        echo '<img src="'.NICED_URL::buildImageURL($file, $protocol).'" '.$attr.' />';
    }

    public static function addCSS($path, $media = "screen")
	{
        self::data()->append("script_css", array(
                                          "path" => $path,
                                          "media" => $media
                                          ));
    }
    
    public static function addCSSForIE( $path,  $ie_version = '', $media = "screen") 
	{
        self::data()->append("script_css_ie", array(
                                             "path" => $path,
                                             "media" => $media,
                                             "ie_version" => $ie_version
                                             ));
    }

    public static function addJs($path, $type="text/javascript") 
	{
        self::data()->append("script_js", array(
                                         "path" => $path,
                                         "type" => $type
                                         ));

    }
   
} //end class

class TM extends Niced_TemplateManager
{
    
}
